package com.ttsx.controller;

import com.ttsx.service.CategoryService;
import com.ttsx.core.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author wb
 * @since 2025-03-11
 */

@RestController
@RequestMapping("category")
public class CategoryController {


    @Autowired
    private CategoryService categoryService;


    @GetMapping("/getCategory")
    public Result<?> getCategory() {
        return Result.success(categoryService.getCategoryList());
    }

    @GetMapping("/exportData")
    public void exportData(HttpServletResponse response) {
        categoryService.exportData(response);
    }

    @PostMapping("/importData")
    public Result<?> importData(@RequestParam("filepath") String filepath) {
        return categoryService.importData(filepath) ? Result.success() : Result.failure();
    }
}
